package com.echo.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.oas.models.media.StringSchema;
import io.swagger.v3.oas.models.Components;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class OpenApiConfig {

    /**
     * 配置全局 OpenAPI 文档信息
     */
    @Bean
    public OpenAPI springOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("Wisdom Cloud Exam Module API")
                        .description("在线考试模块 by echo at 2024")
                        .version("2.0")
                        .contact(new Contact()
                                .name("Zhang Yu")
                                .email("3158779947@qq.com")
                        )
                )
                .servers(List.of(
                        new Server().url("http://localhost:9527").description("本地开发环境")
                ))
                .components(new Components().addParameters("Access-Token",
                        new Parameter()
                                .name("Access-Token")
                                .description("Rest接口权限认证token,无需鉴权可为空")
                                .in("header")
                                .required(false)
                                .schema(new StringSchema())
                ));
    }
}
